using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using DTO;

namespace DAO
{
    public class BaoCaoChiTietThangDAO
    {
        public static bool Delete(BaoCaoChiTietThangDTO bc)
        {
            bool kq = false;
            try
            {
                List<SqlParameter> sqlparam = new List<SqlParameter>();
                sqlparam.Add(new SqlParameter("@MaChiTietDoanhThuThang",bc.MaChiTietDoanhThuThang));

                int n = SqlDataAccessHelper.ExecuteNoneQuery("spBaoCaoChiTietThangDelete",sqlparam);
                if (n == 1)
                    kq = true;
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return kq;
        }
        public static bool Insert(BaoCaoChiTietThangDTO bc)
        {
            bool kq = false;
            try
            {
                List<SqlParameter> sqlparam = new List<SqlParameter>();
                sqlparam.Add(new SqlParameter("@MaChiTietDoanhThuThang", bc.MaChiTietDoanhThuThang));
                sqlparam.Add(new SqlParameter("@MaDoanhThuThang", bc.MaDoanhThuThang));
                sqlparam.Add(new SqlParameter("@Ngay", bc.Ngay));
                sqlparam.Add(new SqlParameter("@SoBenhNhan", bc.SoBenhNhan));
                sqlparam.Add(new SqlParameter("@DoanhThuNgay", bc.DoanhThuNgay));
                sqlparam.Add(new SqlParameter("@TyLe", bc.TyLe));
                int n = SqlDataAccessHelper.ExecuteNoneQuery("spBaoCaoChiTietThangInsert", sqlparam);
                if (n == 1)
                   kq = true;
            }
            catch (Exception ex)
            {
                throw ex;
            }
 
            return kq;
        }
        public static List<BaoCaoChiTietThangDTO> Select()
        {
            List<BaoCaoChiTietThangDTO> lst = new List<BaoCaoChiTietThangDTO>();
            try
            {
                DataTable dt = SqlDataAccessHelper.ExecuteQuery("spBaoCaoChiTietThangSelect");
                foreach (DataRow dr in dt.Rows)
                {
                    BaoCaoChiTietThangDTO bc = new BaoCaoChiTietThangDTO();
                    bc.MaChiTietDoanhThuThang = int.Parse(dr["MaChiTietDoanhThuThang"].ToString());
                    bc.MaDoanhThuThang = int.Parse(dr["MaDoanhThuThang"].ToString());
                    bc.Ngay = DateTime.Parse(dr["Ngay"].ToString());
                    bc.SoBenhNhan = int.Parse(dr["SoBenhNhan"].ToString());
                    bc.DoanhThuNgay = float.Parse(dr["DoanhThuNgay"].ToString());
                    bc.TyLe = float.Parse(dr["TyLe"].ToString());
                    lst.Add(bc);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return lst;
        }
        public static BaoCaoChiTietThangDTO SelectByID(int MaChiTietDoanhThuThang)
        {
            BaoCaoChiTietThangDTO bc = new BaoCaoChiTietThangDTO();
            try
            {
                List<SqlParameter> sqlparam = new List<SqlParameter>();
                sqlparam.Add(new SqlParameter("@MaChiTietDoanhThuThang", MaChiTietDoanhThuThang));

                DataTable dt = SqlDataAccessHelper.ExecuteQuery("spBaoCaoChiTietThangSelectByID",sqlparam);
                DataRow dr = dt.Rows[0];

                bc.MaChiTietDoanhThuThang = int.Parse(dr["MaChiTietDoanhThuThang"].ToString());
                bc.MaDoanhThuThang = int.Parse(dr["MaDoanhThuThang"].ToString());
                bc.Ngay = DateTime.Parse(dr["Ngay"].ToString());
                bc.SoBenhNhan = int.Parse(dr["SoBenhNhan"].ToString());
                bc.DoanhThuNgay = float.Parse(dr["DoanhThuNgay"].ToString());
                bc.TyLe = float.Parse(dr["TyLe"].ToString());
            }
            catch (Exception ex)
            {
                throw ex;
            }

            return bc;            
        }
        public static bool Update(BaoCaoChiTietThangDTO bc)
        {
            bool kq = false;
            try
            {
                List<SqlParameter> sqlparam = new List<SqlParameter>();
                sqlparam.Add(new SqlParameter("@MaChiTietDoanhThuThang", bc.MaChiTietDoanhThuThang));
                sqlparam.Add(new SqlParameter("@MaDoanhThuThang", bc.MaDoanhThuThang));
                sqlparam.Add(new SqlParameter("@Ngay", bc.Ngay));
                sqlparam.Add(new SqlParameter("@SoBenhNhan", bc.SoBenhNhan));
                sqlparam.Add(new SqlParameter("@DoanhThuNgay", bc.DoanhThuNgay));
                sqlparam.Add(new SqlParameter("@TyLe", bc.TyLe));
                int n = SqlDataAccessHelper.ExecuteNoneQuery("spBaoCaoChiTietThangInsert", sqlparam);
                if (n == 1)
                    kq = true;
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return kq;
        }
    }
}
